package com.spring4all.repository;

import com.spring4all.entity.UserDO;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

@Repository
public class UserRepository{

    private final static Map<String, UserDO> userNameMapUser = new HashMap<>();

    static {
        userNameMapUser.put("zhu",new UserDO(1L,"zhu","pass","nick"));
    }

    public UserDO findByUsername(String username){
        System.out.println(userNameMapUser);
        return userNameMapUser.get(username);


    }
    public void save(UserDO userDO){
        if (StringUtils.isEmpty(userDO.getUsername()) || null != userNameMapUser.get(userDO.getUsername())) {
            throw new RuntimeException("用户名不能为空 或者 用户已存在");
        }
        userNameMapUser.put(userDO.getUsername(), userDO);
        System.out.println(userNameMapUser);
    }
}
